//
//  DYDate_CollectionViewCell.m
//  环形进度条
//
//  Created by BetaTheta on 16/4/1.
//  Copyright © 2016年 BetaTheta. All rights reserved.
//

//#define CWIDTH layoutAttributes.size.width
//#define CHIDTH layoutAttributes.size.height

#import "DYDate_CollectionViewCell.h"

@implementation DYDate_CollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

    }
    return self;
}
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
#pragma mark -
    self.trackShapeLayer = [CAShapeLayer layer];
    self.trackShapeLayer.frame = CGRectMake(0, 0, CWIDTH , CWIDTH );//设置shapeLayer的尺寸和位置
    //    self.bgShapeLayer.position = self.view.center;
    self.trackShapeLayer.fillColor = [UIColor clearColor].CGColor;//填充颜色为ClearColor
    
    //设置线条的宽度和颜色
    self.trackShapeLayer.lineWidth = 3.5f;
    self.trackShapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;
    //    self.bgShapeLayer.shadowColor = [[UIColor blackColor] CGColor];
    
    // 指定线的边缘是圆的
    self.trackShapeLayer.lineCap = kCALineCapRound;
    
    //创建出圆形贝塞尔曲线
    UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, CWIDTH , CWIDTH )];
    //让贝塞尔曲线与CAShapeLayer产生联系
    self.trackShapeLayer.path = circlePath.CGPath;
    
    //添加并显示
    [self.contentView.layer addSublayer:self.trackShapeLayer];
    
    
#pragma mark -
    //创建出CAShapeLayer
    self.progressShapeLayer = [CAShapeLayer layer];
    self.progressShapeLayer.frame = CGRectMake(0, 0, CWIDTH , CWIDTH );//设置shapeLayer的尺寸和位置
    
    self.progressShapeLayer.fillColor = [UIColor clearColor].CGColor;//填充颜色为ClearColor
    
    //设置线条的宽度和颜色
    self.progressShapeLayer.lineWidth = 3.0f;
    self.progressShapeLayer.strokeColor = [UIColor orangeColor].CGColor;
    
    // 指定线的边缘是圆的
    self.progressShapeLayer.lineCap = kCALineCapRound;
    
    //创建出圆形贝塞尔曲线
    //    UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 200)];
    
    //让贝塞尔曲线与CAShapeLayer产生联系
    self.progressShapeLayer.path = circlePath.CGPath;
    
    //添加并显示
    [self.trackShapeLayer addSublayer:self.progressShapeLayer];
    
    //    现在我们要用到CAShapeLayer的两个参数，strokeEnd和strokeStart
    //Stroke:用笔画的意思
    //    在这里就是起始笔和结束笔的位置
    //    Stroke为1的话就是一整圈，0.5就是半圈，0.25就是1/4圈。以此类推
    //
    //    如果我们把起点设为0，终点设为0.75
    
    //设置stroke起始点
    self.progressShapeLayer.strokeStart = 0;
    self.progressShapeLayer.strokeEnd = 0.75;
#pragma mark -
    self.circleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CWIDTH - 15, CWIDTH - 15)];
    _circleView.center = self.contentView.center;
    _circleView.layer.cornerRadius = _circleView.bounds.size.width / 2;
    _circleView.backgroundColor = [UIColor orangeColor];
    [_progressShapeLayer addSublayer:_circleView.layer];
    
    self.dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CWIDTH - 15, CWIDTH - 15)];
    _dateLabel.text = @"7";
    _dateLabel.textColor = [UIColor whiteColor];
    
    _dateLabel.textAlignment = NSTextAlignmentCenter;
    [_circleView addSubview:_dateLabel];
    
    

}

@end
